/**
  *@File文件:EvaluateController.java
  *@Date日期:2017年7月21日 下午2:34:12
  *@Copyright版权:Corporation 2017
  */
package com.qiaomengapp.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qiaomengapp.bean.Evaluate;
import com.qiaomengapp.bean.EvaluateList;
import com.qiaomengapp.bean.EvaluateWarp;
import com.qiaomengapp.bean.User;
import com.qiaomengapp.exception.CustomException;
import com.qiaomengapp.service.IEvaluateService;

/**
 * @Description描述:
 * @Author作者 jinxin
 * @Date日期:2017年7月21日
 */
@Controller
@RequestMapping("Evaluate")
public class EvaluateController {
	@Autowired
	private IEvaluateService iEvaluateService;

	// 用户填写评价
	@RequestMapping(value = "writeEvaluate", produces = { "text/html;charset=UTF-8" })
	@ResponseBody
	public String writeEvaluate(HttpSession session, EvaluateList evaluateList) {
		User user = (User) session.getAttribute("user");
		for (Evaluate evaluate : evaluateList.getEvaluates()) {
			evaluate.setUserId(user.getId());
			evaluate.setCreateTime(new Date());
			try {
				iEvaluateService.insert_goodEvaluate(evaluate);
			} catch (CustomException e) {
				// TODO Auto-generated catch block
				return e.getMessage();
			}
		}
		return null;
	}

	// 显示商品的所有评价
	@RequestMapping(value = "goodEvaluates")
	@ResponseBody
	public List<EvaluateWarp> goodEvaluates(Integer shopGoodId) {
		if (shopGoodId==null) {
			shopGoodId=1;
		}
		try {
			List<EvaluateWarp> list = iEvaluateService.select_goodEvaluate(shopGoodId);
			return list;
		} catch (CustomException e) {
			// TODO Auto-generated catch block
			System.out.println(e.getMessage());
		}
		return null;
	}

}
